﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApCableAttachmentStatusMessageFactory
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using System;
using System.Collections.Generic;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

internal class CApCableAttachmentStatusMessageFactory
{
  private List<CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate> m_orderedAttachmentStatusMessage;

  internal CApCableAttachmentStatusMessageFactory(
    CApCableAttachmentStatusAnalysis cableStatusAnalysis)
  {
    this.CableAttachmentStatusAnalysis = cableStatusAnalysis;
    this.InitOrderedAttachmentStatusMessageList();
  }

  public CApCableAttachmentStatusAnalysis CableAttachmentStatusAnalysis { get; set; }

  public CApCableStatusMessage ComputeAttachmentPriorityErrorMessage()
  {
    CApCableStatusMessage priorityErrorMessage = new CApCableStatusMessage();
    for (int index = 0; index < this.m_orderedAttachmentStatusMessage.Count; ++index)
    {
      priorityErrorMessage = this.ComputeErrorMessage(this.m_orderedAttachmentStatusMessage[index]);
      if (priorityErrorMessage.MessageType != CApCableStatusMessageType.None)
        break;
    }
    return priorityErrorMessage;
  }

  private void InitOrderedAttachmentStatusMessageList()
  {
    this.m_orderedAttachmentStatusMessage = new List<CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate>()
    {
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.IsCableAttachmentEditable),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeRetractSystemStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeLocationConflictStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.IsAttachmentFrameEmpty),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeRotatingAndRetractSystemStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeRotatingSlidingAndRetractSystemStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeFixedAndRetractSystemStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.AreRetractSystemValuesValid),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.IsSecondaryAttachmentFrameEmpty),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeAttachmentsLengthStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputePrimaryAndSecondaryFramesStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeDistanceBetweenAttachmentsFrameStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputePercentageLengthAttachmentsStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputePrimaryAndSecondaryFramesAttachmentsStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputePreservedFrameStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeRobotAttachmentFrameStatus),
      new CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate(this.ComputeAttachmentsFrameAttachementStatus)
    };
  }

  private CApCableStatusMessage ComputeErrorMessage(
    CApCableAttachmentStatusMessageFactory.ErrorMessageDelegate errorMessageDelegate)
  {
    CApCableStatusMessage errorMessage = new CApCableStatusMessage();
    if (errorMessageDelegate != null)
      errorMessage = errorMessageDelegate();
    return errorMessage;
  }

  private CApCableStatusMessage ComputeAttachmentsLengthStatus()
  {
    CApCableStatusMessage attachmentsLengthStatus = new CApCableStatusMessage();
    if (!this.CableAttachmentStatusAnalysis.AreAttachmentsLengthSmallerThanCableLength())
    {
      attachmentsLengthStatus.MessageText = CApFLEXStringTable.AttachmentLengthAreInvalid;
      attachmentsLengthStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return attachmentsLengthStatus;
  }

  private CApCableStatusMessage ComputePrimaryAndSecondaryFramesStatus()
  {
    CApCableStatusMessage secondaryFramesStatus = new CApCableStatusMessage();
    CApFLEXAttachmentErrorMessage errorMessage;
    if (!this.CableAttachmentStatusAnalysis.IsLengthBetweenPrimaryAndSecondaryAttachmentValid(out errorMessage))
    {
      secondaryFramesStatus.MessageText = errorMessage.GetErrorMessage();
      secondaryFramesStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return secondaryFramesStatus;
  }

  private CApCableStatusMessage ComputeDistanceBetweenAttachmentsFrameStatus()
  {
    CApCableStatusMessage attachmentsFrameStatus = new CApCableStatusMessage();
    CApFLEXAttachmentErrorMessage attachmentStatus = this.ComputeDistanceBetweenAttachmentsFrameAttachmentStatus();
    attachmentsFrameStatus.MessageText = attachmentStatus.GetErrorMessage();
    attachmentsFrameStatus.MessageType = attachmentStatus.AttachmentErrorType != CApFLEXAttachmentErrorMessage.EAttachmentErrorType.None ? CApCableStatusMessageType.Error : CApCableStatusMessageType.None;
    return attachmentsFrameStatus;
  }

  private CApCableStatusMessage ComputePreservedFrameStatus()
  {
    CApCableStatusMessage preservedFrameStatus = new CApCableStatusMessage();
    CApFLEXAttachmentErrorMessage errorMessage;
    if (!this.CableAttachmentStatusAnalysis.IsEquipmentAttachmentFramePreserved(out errorMessage))
    {
      preservedFrameStatus.MessageText = errorMessage.GetErrorMessage();
      preservedFrameStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    else
    {
      preservedFrameStatus.MessageText = "";
      preservedFrameStatus.MessageType = CApCableStatusMessageType.None;
    }
    return preservedFrameStatus;
  }

  private CApCableStatusMessage ComputePercentageLengthAttachmentsStatus()
  {
    CApCableStatusMessage attachmentsStatus = new CApCableStatusMessage();
    CApFLEXAttachmentErrorMessage errorMessage;
    if (!this.CableAttachmentStatusAnalysis.ArePercentageLengthBetweenAttachmentsValid(out errorMessage))
    {
      attachmentsStatus.MessageText = errorMessage.GetErrorMessage();
      attachmentsStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return attachmentsStatus;
  }

  private CApCableStatusMessage ComputePrimaryAndSecondaryFramesAttachmentsStatus()
  {
    CApCableStatusMessage attachmentsStatus = new CApCableStatusMessage();
    if (this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType3 && !this.CableAttachmentStatusAnalysis.GetFramesAttachedToSameKinematicLinkStatus())
    {
      attachmentsStatus.MessageText = CApFLEXStringTable.PrimarySecondaryFramesNotAttachedToSameKinematicLink;
      attachmentsStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return attachmentsStatus;
  }

  private CApCableStatusMessage ComputeRobotAttachmentFrameStatus()
  {
    CApCableStatusMessage attachmentFrameStatus = new CApCableStatusMessage();
    this.CableAttachmentStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.CableAttachmentStatusAnalysis.StartFrame, out TxRobot _);
    this.CableAttachmentStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.CableAttachmentStatusAnalysis.EndFrame, out TxRobot _);
    if (this.CableAttachmentStatusAnalysis.Location == CApFLEXAttachmentLocation.AlongCable && !this.CableAttachmentStatusAnalysis.AreAttachementFrameValid())
    {
      attachmentFrameStatus.MessageText = CApFLEXStringTable.AttachmentFrameIsNotAttachedMessage;
      attachmentFrameStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    return attachmentFrameStatus;
  }

  private CApCableStatusMessage ComputeAttachmentsFrameAttachementStatus()
  {
    CApCableStatusMessage attachementStatus = new CApCableStatusMessage();
    TxRobot robot1;
    this.CableAttachmentStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.CableAttachmentStatusAnalysis.StartFrame, out robot1);
    TxRobot robot2;
    this.CableAttachmentStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.CableAttachmentStatusAnalysis.EndFrame, out robot2);
    if (!this.CableAttachmentStatusAnalysis.AreAttachmentsAttachedToRobot(!TxRobot.op_Inequality(robot1, (ITxObject) null) ? (ITxObject) robot2 : (ITxObject) robot1))
    {
      attachementStatus.MessageText = CApFLEXStringTable.AttachmentsFrameAreNotAttachedInSameRobotMsg;
      attachementStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    return attachementStatus;
  }

  private CApCableStatusMessage IsCableAttachmentEditable()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (!this.CableAttachmentStatusAnalysis.AttachmentViewModel.IsEditableAttachment)
    {
      cableStatusMessage.MessageText = CApFLEXStringTable.CableAttachmentIsNotEditableWarning;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Warning;
    }
    return cableStatusMessage;
  }

  private CApCableStatusMessage ComputeRetractSystemStatus()
  {
    CApCableStatusMessage retractSystemStatus = new CApCableStatusMessage();
    List<CApFLEXAttachmentType> attachmentTypes = new List<CApFLEXAttachmentType>(3)
    {
      CApFLEXAttachmentType.RetractSystemType1,
      CApFLEXAttachmentType.RetractSystemType2,
      CApFLEXAttachmentType.RetractSystemType3
    };
    if (attachmentTypes.FindIndex((Predicate<CApFLEXAttachmentType>) (t => t == this.CableAttachmentStatusAnalysis.AttachmentType)) != -1 && this.CableAttachmentStatusAnalysis.IsThereSomeAttachmentOfTypes(attachmentTypes))
    {
      retractSystemStatus.MessageText = CApFLEXStringTable.MoreThanOneRetractSystemAttachmentErrorMessage;
      retractSystemStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return retractSystemStatus;
  }

  private CApCableStatusMessage ComputeLocationConflictStatus()
  {
    CApCableStatusMessage locationConflictStatus = new CApCableStatusMessage();
    if (this.CableAttachmentStatusAnalysis.Location == CApFLEXAttachmentLocation.Start && this.CableAttachmentStatusAnalysis.IsThereSomeAttachmentAtLocation(CApFLEXAttachmentLocation.Start))
    {
      locationConflictStatus.MessageText = CApFLEXStringTable.MoreThanOneAttachmentAtStartErrorMessage;
      locationConflictStatus.MessageType = CApCableStatusMessageType.Error;
    }
    else if (this.CableAttachmentStatusAnalysis.Location == CApFLEXAttachmentLocation.End && this.CableAttachmentStatusAnalysis.IsThereSomeAttachmentAtLocation(CApFLEXAttachmentLocation.End))
    {
      locationConflictStatus.MessageText = CApFLEXStringTable.MoreThanOneAttachmentAtEndErrorMessage;
      locationConflictStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return locationConflictStatus;
  }

  private CApCableStatusMessage ComputeRotatingAndRetractSystemStatus()
  {
    return this.ComputePointAndRetractSystemStatus(CApFLEXAttachmentType.Rotating);
  }

  private CApCableStatusMessage ComputeRotatingSlidingAndRetractSystemStatus()
  {
    return this.ComputePointAndRetractSystemStatus(CApFLEXAttachmentType.RotatingSliding);
  }

  private CApCableStatusMessage ComputeFixedAndRetractSystemStatus()
  {
    return this.ComputePointAndRetractSystemStatus(CApFLEXAttachmentType.Fixed);
  }

  private CApCableStatusMessage ComputePointAndRetractSystemStatus(
    CApFLEXAttachmentType pointAttachmentType)
  {
    CApCableStatusMessage retractSystemStatus = new CApCableStatusMessage();
    List<CApFLEXAttachmentType> attachmentTypes = new List<CApFLEXAttachmentType>(3)
    {
      CApFLEXAttachmentType.RetractSystemType2,
      CApFLEXAttachmentType.RetractSystemType3
    };
    if (this.CableAttachmentStatusAnalysis.AttachmentType == pointAttachmentType && this.CableAttachmentStatusAnalysis.IsThereSomeAttachmentOfTypes(attachmentTypes) || this.CableAttachmentStatusAnalysis.IsAttachmentOfTypes(attachmentTypes) && this.CableAttachmentStatusAnalysis.IsThereSomeAttachmentOfType(pointAttachmentType))
    {
      CApFLEXAttachmentErrorMessage attachmentDistanceStatus = this.ComputePointAndRetractSystemAttachmentDistanceStatus(pointAttachmentType);
      if (attachmentDistanceStatus.AttachmentErrorType != CApFLEXAttachmentErrorMessage.EAttachmentErrorType.None)
      {
        retractSystemStatus.MessageText = attachmentDistanceStatus.GetErrorMessage();
        retractSystemStatus.MessageType = CApCableStatusMessageType.Error;
      }
    }
    return retractSystemStatus;
  }

  private CApCableStatusMessage AreRetractSystemValuesValid()
  {
    bool flag = true;
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType2)
    {
      if (!this.CableAttachmentStatusAnalysis.IsRetractSystemMinMaxValid())
      {
        flag = false;
        cableStatusMessage.MessageText = CApFLEXStringTable.MinMaxRetractLengthInvalidErrorMessage;
        cableStatusMessage.MessageType = CApCableStatusMessageType.Error;
      }
      if (flag && !this.CableAttachmentStatusAnalysis.IsRetractSystemType2MinMaxAndDistanceFromStartValid())
      {
        cableStatusMessage.MessageText = CApFLEXStringTable.MinMaxAndDistanceFromStartRetractSystemInvalidErrorMessage;
        cableStatusMessage.MessageType = CApCableStatusMessageType.Error;
      }
    }
    else if (this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType3)
    {
      if (!this.CableAttachmentStatusAnalysis.AreRetractSystemType3DistancesFromStartValid())
      {
        flag = false;
        cableStatusMessage.MessageText = CApFLEXStringTable.PrimarySecondaryDistanceFromStartInvalidErrorMessage;
        cableStatusMessage.MessageType = CApCableStatusMessageType.Error;
      }
      if (flag && !this.CableAttachmentStatusAnalysis.IsRetractSystemMinMaxValid())
      {
        flag = false;
        cableStatusMessage.MessageText = CApFLEXStringTable.MinMaxRetractLengthInvalidErrorMessage;
        cableStatusMessage.MessageType = CApCableStatusMessageType.Error;
      }
      if (flag && !this.CableAttachmentStatusAnalysis.IsRetractSystemType3MinMaxAndSecondaryDistanceFromStartValid())
      {
        cableStatusMessage.MessageText = CApFLEXStringTable.MinMaxAndSecondaryDistanceFromStartRetractSystemInvalidErrorMessage;
        cableStatusMessage.MessageType = CApCableStatusMessageType.Error;
      }
    }
    return cableStatusMessage;
  }

  private CApCableStatusMessage IsAttachmentFrameEmpty()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.CableAttachmentStatusAnalysis.FixedFrame == null || this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType3 && this.CableAttachmentStatusAnalysis.SecondaryFixedFrame == null)
    {
      string str = CApFLEXStringTable.CurrentAttachmentFrameMissingMessage;
      if (this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType3)
        str = CApFLEXStringTable.CurrentAttachmentFramesMissingMessage;
      cableStatusMessage.MessageText = str;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Incomplet;
    }
    return cableStatusMessage;
  }

  private CApCableStatusMessage IsSecondaryAttachmentFrameEmpty()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType3 && this.CableAttachmentStatusAnalysis.SecondaryFixedFrame == null)
    {
      cableStatusMessage.MessageText = CApFLEXStringTable.CurrentAttachmentFramesMissingMessage;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Incomplet;
    }
    return cableStatusMessage;
  }

  private CApFLEXAttachmentErrorMessage ComputePointAndRetractSystemAttachmentDistanceStatus(
    CApFLEXAttachmentType pointAttachmentType)
  {
    CApFLEXAttachmentErrorMessage attachmentDistanceStatus = new CApFLEXAttachmentErrorMessage()
    {
      AttachmentType = this.CableAttachmentStatusAnalysis.AttachmentType
    };
    double lowerBound;
    double upperBound;
    if (!this.CableAttachmentStatusAnalysis.IsPointAndRetractSystemAttachementDistanceValid(out lowerBound, out upperBound))
    {
      if (this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType2 || this.CableAttachmentStatusAnalysis.AttachmentType == CApFLEXAttachmentType.RetractSystemType3)
      {
        attachmentDistanceStatus.AttachmentErrorType = this.ComputePointAttachmentAndRetractSystemErrorType(pointAttachmentType);
        attachmentDistanceStatus.LowerBound = lowerBound;
        attachmentDistanceStatus.UpperBound = upperBound;
      }
      else
      {
        attachmentDistanceStatus.AttachmentErrorType = this.ComputeRetractSystemAndPointAttachmentErrorType(pointAttachmentType);
        attachmentDistanceStatus.LowerBound = lowerBound;
        attachmentDistanceStatus.UpperBound = upperBound;
      }
    }
    return attachmentDistanceStatus;
  }

  private CApFLEXAttachmentErrorMessage.EAttachmentErrorType ComputePointAttachmentAndRetractSystemErrorType(
    CApFLEXAttachmentType pointAttachmentType)
  {
    switch (pointAttachmentType)
    {
      case CApFLEXAttachmentType.Fixed:
        return CApFLEXAttachmentErrorMessage.EAttachmentErrorType.ExistingFixedAttachmentAndRetractSystemError;
      case CApFLEXAttachmentType.Rotating:
        return CApFLEXAttachmentErrorMessage.EAttachmentErrorType.ExistingRotatingAttachmentAndRetractSystemError;
      case CApFLEXAttachmentType.RotatingSliding:
        return CApFLEXAttachmentErrorMessage.EAttachmentErrorType.ExistingRotatingSlidingAttachmentAndRetractSystemError;
      default:
        throw new NotImplementedException();
    }
  }

  private CApFLEXAttachmentErrorMessage.EAttachmentErrorType ComputeRetractSystemAndPointAttachmentErrorType(
    CApFLEXAttachmentType pointAttachmentType)
  {
    switch (pointAttachmentType)
    {
      case CApFLEXAttachmentType.Fixed:
        return CApFLEXAttachmentErrorMessage.EAttachmentErrorType.ExistingRetractSystemAndFixedAttachmentError;
      case CApFLEXAttachmentType.Rotating:
        return CApFLEXAttachmentErrorMessage.EAttachmentErrorType.ExistingRetractSystemAndRotatingAttachmentError;
      case CApFLEXAttachmentType.RotatingSliding:
        return CApFLEXAttachmentErrorMessage.EAttachmentErrorType.ExistingRetractSystemAndRotatingSlidingAttachmentError;
      default:
        throw new NotImplementedException();
    }
  }

  private CApFLEXAttachmentErrorMessage ComputeDistanceBetweenAttachmentsFrameAttachmentStatus()
  {
    List<CApFLEXAttachment> capFlexAttachmentList = new List<CApFLEXAttachment>((IEnumerable<CApFLEXAttachment>) this.CableAttachmentStatusAnalysis.AttachmentDataList);
    if (!capFlexAttachmentList.Any<CApFLEXAttachment>((Func<CApFLEXAttachment, bool>) (a => a.Location == CApFLEXAttachmentLocation.Start)))
      capFlexAttachmentList.Insert(0, (CApFLEXAttachment) new CApFLEXMockAttachment((ICApCableExtentDescriptor) this.CableAttachmentStatusAnalysis.AttributeViewModel, CApFLEXAttachmentLocation.Start));
    if (!capFlexAttachmentList.Any<CApFLEXAttachment>((Func<CApFLEXAttachment, bool>) (a => a.Location == CApFLEXAttachmentLocation.End)))
      capFlexAttachmentList.Add((CApFLEXAttachment) new CApFLEXMockAttachment((ICApCableExtentDescriptor) this.CableAttachmentStatusAnalysis.AttributeViewModel, CApFLEXAttachmentLocation.End));
    bool flag1 = true;
    CApFLEXAttachmentErrorMessage attachmentStatus = new CApFLEXAttachmentErrorMessage()
    {
      AttachmentType = this.CableAttachmentStatusAnalysis.AttachmentType
    };
    int currentAttachmentRank = CApCableAttachmentStatusAnalysis.ComputeCurrentAttachmentRank(this.CableAttachmentStatusAnalysis.LengthFromStart, capFlexAttachmentList);
    for (int index = 0; flag1 && index < capFlexAttachmentList.Count; ++index)
      flag1 = capFlexAttachmentList[index].FixedFrame != this.CableAttachmentStatusAnalysis.FixedFrame;
    if (currentAttachmentRank == 0 || currentAttachmentRank >= capFlexAttachmentList.Count)
      flag1 = false;
    if (flag1)
    {
      bool flag2 = false;
      bool flag3 = false;
      double num1 = 0.0;
      double num2 = 0.0;
      bool flag4 = true;
      try
      {
        double distance1;
        if (CApCableUtility.ComputeDistanceBetweenFrames(capFlexAttachmentList[currentAttachmentRank - 1].FixedFrame, this.CableAttachmentStatusAnalysis.ClosestFrameToStart, out distance1))
        {
          num1 = capFlexAttachmentList[currentAttachmentRank - 1].LengthFromStart - capFlexAttachmentList[currentAttachmentRank - 1].RetractionCapability + distance1;
          flag3 = this.CableAttachmentStatusAnalysis.LowerLengthFromStart < num1;
        }
        double distance2;
        if (CApCableUtility.ComputeDistanceBetweenFrames(this.CableAttachmentStatusAnalysis.FixedFrame, capFlexAttachmentList[currentAttachmentRank].ClosestFrameToStart, out distance2))
        {
          num2 = capFlexAttachmentList[currentAttachmentRank].LowerLengthFromStart + this.CableAttachmentStatusAnalysis.RetractionCapability - distance2;
          flag2 = this.CableAttachmentStatusAnalysis.LengthFromStart > num2;
        }
      }
      catch (TxFailedToCalculateMinimalDistanceFromObjectException ex)
      {
        flag4 = false;
      }
      if (flag4)
      {
        if (flag3 & flag2)
        {
          attachmentStatus.DistanceFromAttachment1 = 0.0;
          attachmentStatus.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.MinMax;
          attachmentStatus.AttachmentErrorType = CApFLEXAttachmentErrorMessage.EAttachmentErrorType.CanNotCreateAttachmentError;
        }
        else
        {
          if (flag3)
          {
            attachmentStatus.DistanceFromAttachment1 = num1;
            attachmentStatus.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.Minimum;
            int num3 = currentAttachmentRank - 1;
            attachmentStatus.AttachFrame1 = num3 != 0 ? "attachment #" + num3.ToString() : "cable start";
            attachmentStatus.AttachmentErrorType = this.CableAttachmentStatusAnalysis.MinimumDistanceErrorType;
          }
          if (flag2)
          {
            attachmentStatus.DistanceFromAttachment1 = num2;
            attachmentStatus.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.Maximum;
            int num4 = currentAttachmentRank;
            attachmentStatus.AttachFrame1 = currentAttachmentRank != capFlexAttachmentList.Count - 1 ? "attachment #" + num4.ToString() : "cable end";
            attachmentStatus.AttachmentErrorType = CApFLEXAttachmentErrorMessage.EAttachmentErrorType.AttachmentDistanceError;
          }
        }
      }
      else
        attachmentStatus.AttachmentErrorType = CApFLEXAttachmentErrorMessage.EAttachmentErrorType.AttachmentDistanceError;
    }
    return attachmentStatus;
  }

  private delegate CApCableStatusMessage ErrorMessageDelegate();
}
